package net.chathu.airgw.packets.chat 
{
	import net.chathu.airgw.model.JoinedRoomInfo;
	import net.chathu.airgw.model.Room;
	import net.chathu.airgw.model.User;
	import net.chathu.airgw.packets.gw.serverpackets.ChannelModeChangePacket;
	/**
	 * ...
	 * @author ze
	 */
	public class IChgUsers extends ChatPacket
	{
		
		public function IChgUsers() 
		{
			
		}
		
		override public function execute():void
		{
			var userId:int = data[2];
			
			var user:User = User(sessionData.chatData.users.getUser(userId));
			
			if (user)
			{
				var changedValue:String = data[3];
				
				switch(changedValue)
				{
					case User.KEY_COLOR:
						//trace(user.name + " uj szine: " + data[4]);
						user.color = data[4];
					break;
					
					case User.KEY_DISTURB:
						//trace(user.name + " disturb: " + data[4]);
						user.disturb = data[4];
					break;
					
					case User.KEY_SILENCE:
						///trace(user.name + " silence: " + data[4]);
						var silenced:Boolean = (data[4] == "0");
						user.silenced = silenced;
						
						var sameRooms:Array = sessionData.chatData.getCommonJoinedRoomsWithUser(userId);
						for each (var joinedRoom:JoinedRoomInfo in sameRooms) 
						{
							var room:Room = sessionData.chatData.rooms.getRoom(joinedRoom.roomId);
							if (room)
							{
								sendToClient(new ChannelModeChangePacket(room.name, (silenced ? " +b " : " -b ") + user.name + "!*flood.silence"));
							} else {
								trace("Missing room, roomId: " + joinedRoom.roomId + "(IChgUsers)");
							}
						}
					break;
				}
			} else {
				trace("Missing user, userId: " + userId + "(IChgUsers)");
			}
		}
		
	}

}